package com.lovetemperature.action;

import com.lovetemperature.model.Member;
import com.lovetemperature.service.MemberService;
import com.opensymphony.xwork2.ActionSupport;

public class RegisterAction extends ActionSupport {
	private MemberService memberService;
	private Member member;
	private String message;
	private String result;

	@Override
	public String execute() throws Exception {
		if(!checkNotNull()){
			message = "必填项目中有空，请重试";
			result = "fail";
			return "json";
		}
		if(memberService.register(member)){
			message = "注册成功";
			result = "success";
			return "json";
		}else {
			message = "该邮箱已经注册过，请换一个";
			result = "fail";
			return "json";
		}
	}

	private boolean checkNotNull(){
		if(member==null){
			return false;
		}
		if(member.getName()==null || member.getPassword()==null || member.getEmail()==null){
			return false;
		}
		if(member.getName().equalsIgnoreCase("") || member.getPassword().equalsIgnoreCase("") || member.getEmail().equalsIgnoreCase("")){
			return false;
		}
		return true;
	}

	public MemberService getMemberService() {
		return memberService;
	}

	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}

	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

}
